<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;
use think\model\relation\BelongsTo;

/**
 * @mixin \think\Model
 */
class AdminProblemArticle extends Model
{
    //
    const FLAG_ARR = [1 => '热门问题', 2 => '常见问题'];
    protected $autoWriteTimestamp = true;

    public function type(): BelongsTo {
        return $this->belongsTo(AdminProblemType::class, 'problem_id')
            ->where('is_delete', 0)->bind([
            'problem_type' => 'title'
        ]);
    }

    public function getFlagTextAttr($value, $data)
    {
        return self::FLAG_ARR[$data['flag']];
    }

    public function getContentAttr($value)
    {
        return htmlspecialchars_decode($value);
    }
}
